/*
 * @Author: LiJia
 * @Date: 2021-03-04 13:31:23
 * @LastEditTime: 2021-03-29 05:43:59
 * @LastEditors: LiJia
 * @Description: Description
 * @FilePath: \class-manage-system\miniprogram\pages\main\main.ts
 */
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageConfig: {
      // currentPage: "minePage",
      currentPage: "sourcesPage",

      sourcesPage: {
        isCurrent: false,
        childrenPage: {}
      },
      messagesPage: {
        isCurrent: false,
        childrenPage: {}
      },
      minePage: {
        isCurrent: false,
        childrenPage: {}
      }
    },
    clsUserInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    // console.log(option)
    const eventChannel = this.getOpenerEventChannel()
    let clsUserInfo = {}
    eventChannel.on('clsUserInfo', (req) => {
      clsUserInfo = req.data
    })
    // eventChannel.on('page-change', (req) => {
    //   console.log(req)
    // })
    console.log(this.data.pageConfig.currentPage)
    // let isCurrent = 'pageConfig.minePage.isCurrent'
    let isCurrent = 'pageConfig.sourcesPage.isCurrent'
    this.setData({
      [isCurrent]: true,
      clsUserInfo: clsUserInfo
    })
  },
  // 更新当前页面数值，修改当前页面key
  handlePageChange(event: any) {
    let oldCurrentPage = this.data.pageConfig.currentPage
    let newCurrentPage = event.detail.currentPage
    if (oldCurrentPage === newCurrentPage) {
      return
    } else {
      let oldIsCurrentKey = 'pageConfig.' + oldCurrentPage + '.isCurrent'
      let newIsCurrentKey = 'pageConfig.' + newCurrentPage + '.isCurrent'
      this.setData({
        [oldIsCurrentKey]: false,
        [newIsCurrentKey]: true
      })
      let currentPageKey = 'pageConfig.currentPage'
      this.setData({
        [currentPageKey]: event.detail.currentPage
      })
    }
  },
  roleChange() {
    const messagePage = this.selectComponent('#messagePage')
    messagePage.getMessageList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {};
  }
})
